package com.yuebu.bluetoothbandsdk;
import android.annotation.SuppressLint;
import android.app.Notification;
import android.os.Bundle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;

import org.greenrobot.eventbus.EventBus;

@SuppressLint("OverrideAbstract")
public class MyNotificationListenerService extends NotificationListenerService {
    private static final String TAG = "MyNotificationListenerS";
    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        super.onNotificationPosted(sbn);
        Bundle extras = sbn.getNotification().extras;
        String title = extras.getString(Notification.EXTRA_TITLE);
        String content = extras.getString(Notification.EXTRA_TEXT);
        MsgBean bean = null;
        switch (sbn.getPackageName()) {
            case "com.tencent.mm":
                bean = new MsgBean(2, title, content);
                break;
            case "com.android.mms":
                Log.i("短信", content);
                bean = new MsgBean(1, title, content);
                break;
            case "com.tencent.mobileqq":
                Log.i("qq", content);
                bean = new MsgBean(3, title, content);
                break;
            case "com.tencent.tim":
                Log.i("tim", content);
                break;
            case "com.android.incallui":
                bean = new MsgBean(0, title, content);
                Log.i("电话", content);
                break;
        }
        if (bean != null) {
            EventBus.getDefault().post(bean);
        }
    }
}